home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_06 / lawless / fterm.c < prev   
C/C++ Source or Header  |  1995-03-28  |  2KB  |  87 lines

  1. ----------------------- Listing 1: Bare-bones FOSSIL Program ---------
  2.  
  3. // Bare bones FOSSIL terminal program.
  4. // Compiled with Microsoft VC++ 1.0, but should
  5. // port to other compilers.
  6.  
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <conio.h>
  10.  
  11. typedef unsigned char BYTE;
  12. typedef unsigned int  WORD;
  13.  
  14. // Extended key code for
  15. // Alt-X
  16. #define ALT_X (0x2d)
  17. #define SER_DAT_READY (0x100)
  18.  
  19. int def_port=0;
  20.  
  21.  
  22. // Generalized FOSSIL function
  23. //          AH   AL   DX
  24. WORD fossil(BYTE,BYTE,WORD);
  25.  
  26.  
  27. // Specific FOSSIL functions actually implemented
  28. // as macros
  29. #define fos_setparms(p,x) fossil(0,x,p)
  30. #define fos_putc(p,c)     fossil(1,c,p)
  31. #define fos_getc(p)       fossil(2,0,p)
  32. #define fos_status(p)     fossil(3,0,p)
  33. #define fos_init(p)       fossil(4,0,p)
  34. #define fos_uninit(p)     fossil(5,0,p)
  35. #define fos_setDTR(p,f)   fossil(6,f,p)
  36.  
  37. main(int argc,char **argv)
  38. {
  39.    int c;
  40.  
  41.    if(fos_init(def_port)!=0x1954) {
  42.       fprintf(stderr,
  43.          "\nFOSSIL driver not present!\n");
  44.       exit(1);
  45.    }
  46.  
  47.    // Set Parms 9600,N,8,1
  48.    fos_setparms(def_port,0xe3);
  49.  
  50.    // Main Terminal Loop
  51.    while(1) {
  52.       if(kbhit()) {
  53.          c=getch();
  54.          if(!c) {
  55.             if(getch()==ALT_X)
  56.                break;
  57.          }
  58.          else
  59.             fos_putc(def_port,(BYTE)c);
  60.       }
  61.  
  62.       // See if a character is waiting to be read
  63.       // If so, display it.
  64.       if((fos_status(def_port)&SER_DAT_READY)!=0) {
  65.          fputc(fos_getc(def_port),stdout);
  66.       }
  67.    }
  68.    // Lower DTR
  69.    fos_setDTR(def_port,0);
  70.    // Uninitialize Driver
  71.    fos_uninit(def_port);
  72.    exit(0);
  73. }
  74.  
  75. // Use older interrupt interface rather than
  76. // inline assembly.
  77. WORD fossil (BYTE ahreg,BYTE alreg, WORD dxreg)
  78. {
  79.    union REGS r;
  80.    r.h.ah=ahreg;
  81.    r.h.al=alreg;
  82.    r.x.dx=dxreg;
  83.    int86(0x14,&r,&r);
  84.    return(r.x.ax);
  85. }
  86.  
  87.